package com.wj.rspmproperty.controller;

import com.wj.rspmproperty.pojo.PageResult;
import com.wj.rspmproperty.pojo.ResponsePojo;
import com.wj.rspmproperty.pojo.vo.PayInfo;
import com.wj.rspmproperty.service.PayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * @author WeiJin
 * @version 1.0
 */
@RestController
@RequestMapping("/pay")
@Api(tags = "支付信息API")
public class PayController {
    @Autowired
    private PayService payService;

    @GetMapping("/payInfos")
    @ApiOperation("支付信息分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数",
                    dataTypeClass = Integer.class, defaultValue = "1"),
            @ApiImplicitParam(name = "size", value = "每页多少条记录",
                    dataTypeClass = Integer.class, defaultValue = "10"),
            @ApiImplicitParam(name = "start", value = "开始日期",dataTypeClass = LocalDate.class),
            @ApiImplicitParam(name = "end", value = "结束日期",dataTypeClass = LocalDate.class),
            @ApiImplicitParam(name = "username", value = "用户姓名"),
            @ApiImplicitParam(name = "idCard", value = "身份证"),
            @ApiImplicitParam(name = "floorId", value = "楼层id"),
            @ApiImplicitParam(name = "buildingId", value = "建筑id"),
    })
    public ResponsePojo<PageResult<PayInfo>> getPaysInfo(
            @RequestParam(defaultValue = "1") Integer current,
            @RequestParam(defaultValue = "10") Integer size,
            @RequestParam(value = "start",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate start,
            @RequestParam(value = "end",required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate end,
            @RequestParam(value = "username",required = false) String username, @RequestParam(value = "idCard",required = false) String idCard,
            @RequestParam(value = "floorId",required = false) Integer floorId, @RequestParam(value = "buildingId",required = false) Integer buildingId
    ) {
        if (start != null & end == null) {
            end = LocalDate.now();
        }
        PageResult<PayInfo> page =
                payService.pageOfPayInfo(current, size, start, end, username, idCard, floorId, buildingId);
        return ResponsePojo.success(page);
    }
}
